<template>
  <div class="page-root">
    <BasePanel>
        <a-button type="primary" @click="back">
            返回
        </a-button>
      <a-tabs class="tabs-wrap" v-model="tabIndex">
        <a-tab-pane key="0" tab="任务详情">
          <div class="details_box">
            <div class="details_box_right">
              <div class="details_box_right_img">
                <img :src="processImage(detailsInfo.goods_image)" alt="" />
                <div class="extend">
                  <div></div>
                  <span>已有{{detailsInfo.anchor_no_num}}位分销者参与该推广</span>
                </div>
              </div>
              <div class="mission_subsidy">
                完成任务补贴：<span>¥</span><span>{{ detailsInfo.promotion_money-0 }}</span>
              </div>
            </div>
            <div class="details_box_left">
              <div class="saleroom">
                <img src="@/assets/img/home/home_icon.png" alt="" />
                <span>目标总销售额：</span>
                <span>¥</span><span>{{ detailsInfo.sale_money }}</span>
              </div>
              <div class="task_name">
                任务名称：{{ detailsInfo.title }}
              </div>
              <div class="task_name">
                产品名称：{{ detailsInfo.goods_title }}
              </div>
              <!-- <div class="task_name">店铺名称：好运来旗舰店</div> -->
              <div class="scale_saleroom_box">
                <div class="scale_box">
                  <div class="mission_subsidy">
                    <p><span>{{ detailsInfo.promotion_money_rate-0 }}</span><span>%</span></p>
                    <p>任务补贴比例</p>
                  </div>
                  <div class="mission_subsidy">
                    <p><span>{{ detailsInfo.commission_rate-0 }}</span><span>%</span></p>
                    <p>任务达人佣金</p>
                  </div>
                  <div class="mission_subsidy">
                    <p><span>{{ detailsInfo.promotion_rate-0 }}</span><span>%</span></p>
                    <p>任务服务费</p>
                  </div>
                </div>
                <div class="saleroom_box">
                  <div class="mission_subsidy">
                    <p><span>{{ detailsInfo.last_sale_money }}</span><span>元</span></p>
                    <p>剩余可领取销售额</p>
                  </div>
                  <div class="mission_subsidy">
                    <p><span>{{ detailsInfo.sale_money_received_rate-0 }}</span><span>%</span></p>
                    <p>销售额已领取</p>
                  </div>
                </div>
              </div>
              <div class="task_name">截止时间: {{ detailsInfo.end_time }}</div>
              <div class="task_btn">
                <div class="dedicated_task" @click="get_task(2)">申请专属任务</div>
                <div class="get_task" v-if="detailsInfo.receive_status == -1" @click="get_task(-1)">领取任务</div>
                <div class="get_task" v-else-if="detailsInfo.receive_status == 1 || detailsInfo.receive_status == 2" @click="get_task(1)">立即申样</div>
                <!-- <div class="share_tasks">分享任务</div> -->
              </div>
            </div>
          </div>
          <div class="details_tips">
            <div class="details_tips_title">
              <div>*任务规则：</div>
              <div>1.分销者领取任务销售额后，须在7天内给达人申样通过，否则任务失效。</div>
              <div>2.在任务截止时间内，未完成领取的目标销售额（按结算金额计算），则无法领取任务补贴。</div>
              <div>3.在任务截止时间内，完成大于等于领取目标销售额的80%，可在剩余可领取销售额内申请提额，按任务补贴比例结算对应的补贴金额</div>
              <div>4.领取任务后，可在【我的】页面——【我的团队】中邀请队员一起完成任务</div>
            </div>
          </div>
        </a-tab-pane>
      </a-tabs>
    </BasePanel>
    <FormModal :visible="formShow" :default="defaultObj" :task_uuid="task_id" @success="successForm" :level_task_commission_rate="detailsInfo.level_task_commission_rate" @close="closeForm" />
    <FormModal1 :visible="formShow1" :default="defaultObj1" :task_uuid="task_id" @success="successForm1"  @close="closeForm1" :detailsInfo="detailsInfo" />
    <FormModal2 :visible="formShow2" :default="defaultObj2" :task_uuid="task_id" @success="successForm2"  @close="closeForm2" :detailsInfo="detailsInfo" />
  </div>
</template>
  
  <script>
import {mapState, mapGetters } from "vuex";
import * as Ajax from "@/api/channel";
import FormModal from './form';
import FormModal1 from './form1';
import FormModal2 from './form2';
export default {
  components: {
    FormModal,
    FormModal1,
    FormModal2
  },
  data() {
    return {
      tabIndex: "0",
      detailsInfo: {},
      formShow: false,
      defaultObj: {},
      task_id: "",
      formShow1: false,
      defaultObj1: {},
      formShow2: false,
      defaultObj2: {},
    };
  },
  computed: {
    ...mapGetters("user", ["getCdnUrl"]),
    ...mapState('missionHall', ['detailsShow', 'task_uuid']),
  },
  created() {
    // this.task_uuid = this.$route.query.task_uuid;
    this.task_id = this.task_uuid
    this.tableInit();
  },
  methods: {
    //图片校验方法
    processImage(imageUrl) {

      if (imageUrl === undefined || imageUrl === null) {
        return ""; // 或者返回一个默认的 URL
      }

      if (!imageUrl.startsWith("http")) {
        return this.getCdnUrl + imageUrl;
      }
      return imageUrl;
    },
    updateTable(params = {}) {
      this.searchForm = { ...params };
      this.pageKey = this.$options.data().pageKey;
      this.tableInit();
    },
    // 当天日期
    getFormattedDate(type) {
      const today = new Date();
      const year = today.getFullYear();
      const month = String(today.getMonth() + 1).padStart(2, "0");
      const day = String(today.getDate()).padStart(2, "0");

      if (type === "start") {
        return `${year}-${month}-${day} 00:00:00`;
      } else if (type === "end") {
        return `${year}-${month}-${day} 23:59:59`;
      }
    },
    // table 初始化
    tableInit() {
      this.loading = true;
      const params = { task_uuid: this.task_uuid };

      Ajax.merchantTaskInfo(params)
        .then((res) => {
          if (res.error === 0) {
            this.detailsInfo = res.data;
          }
        })
        .finally(() => {
          this.loading = false;
        });
    },
    back() {
      this.$emit('back');
    },
    successForm() {
      this.tableInit();
      this.closeForm();
      this.formShow1 = true;
    },
    successForm1() {
      this.closeForm1();
    },
    successForm2() {
      this.closeForm2();
    },
    closeForm() {
      this.formShow = false;
      this.defaultObj = {};
    },
    closeForm1() {
      this.formShow1 = false;
      this.defaultObj1 = {};
    },
    closeForm2() {
      this.formShow2 = false;
      this.defaultObj2 = {};
    },
    get_task(value) {
      if (value == -1) {
        this.formShow = true;
      }else if(value == 1){
        this.formShow1 = true;
      }else {
        this.formShow2 = true;
      }
    },
  },
};
</script>
  
  <style lang="scss" scoped>
.details_box {
  display: flex;
  .details_box_right {
    .details_box_right_img {
      position: relative;
      width: 228px;
      height: 228px;
      border-radius: 12px;
      img {
        width: 100%;
        height: 100%;
        border-radius: 12px;
        object-fit: contain;
      }
      .extend {
        position: absolute;
        top: 6px;
        left: 6px;
        display: flex;
        align-items: center;
        width: 163px;
        height: 26px;
        border-radius: 4px;
        background: rgba(0, 0, 0, 0.4);
        div {
          width: 5px;
          height: 5px;
          background: #ffffff;
          border-radius: 50%;
          margin:0 6px;
        }
        span {
          font-weight: 400;
          font-size: 12px;
          color: #ffffff;
        }
      }
    }
    .mission_subsidy {
      width: 228px;
      margin-top: 14px;
      text-align: center;
      font-weight: 400;
      font-size: 14px;
      color: #666666;
      span {
        font-weight: 600;
        font-size: 14px;
        color: #e33b35;
      }
      span:nth-child(2) {
        font-weight: 600;
        font-size: 20px;
        color: #e33b35;
      }
    }
  }
  .details_box_left {
    margin-left: 12px;
    .saleroom {
      width: 194px;
      height: 24px;
      background: linear-gradient(
        270deg,
        rgba(255, 255, 255, 0) 0%,
        #ffe193 100%
      );
      border-radius: 4px;
      display: flex;
      align-items: center;
      padding: 6px;
      margin-bottom: 8px;
      img {
        width: 13px;
        height: 13px;
        margin-right: 4px;
      }
      span {
        font-weight: 400;
        font-size: 13px;
        color: #9b4309;
      }
      span:nth-child(3) {
        font-weight: 600;
        font-size: 10px;
        color: #9b4309;
      }
      span:nth-child(4) {
        font-weight: 600;
        font-size: 13px;
        color: #9b4309;
      }
    }
    .task_name {
      font-weight: 400;
      font-size: 14px;
      color: #000000;
      margin-bottom: 8px;
    }
    .scale_saleroom_box {
      display: flex;
      margin-bottom: 8px;
      .scale_box,
      .saleroom_box {
        width: 360px;
        height: 57px;
        background: #f5f5f5;
        border-radius: 6px;
        margin-right: 14px;
        display: flex;
        padding: 7px 10px;
        box-sizing: border-box;
        .mission_subsidy {
          flex: 1;
          p:nth-child(1) {
            text-align: center;
            margin: 0;
            span:nth-child(1) {
              font-weight: 600;
              font-size: 14px;
              color: #000000;
            }
            span:nth-child(2) {
              font-weight: 400;
              font-size: 9px;
              color: #000000;
            }
          }
          p:nth-child(2) {
            font-weight: 400;
            font-size: 10px;
            color: #999999;
            margin: 0;
            text-align: center;
          }
        }
      }
      .saleroom_box {
        width: 240px;
        height: 57px;
        background: #f5f5f5;
        border-radius: 6px;
      }
      
    }
    .task_btn {
        display: flex;
        align-items: center;
        margin-top: 16px;
        .dedicated_task {
            width: 130px;
            height: 34px;
            background: #1890FF;
            border-radius: 6px;
            font-weight: 400;
            font-size: 15px;
            color: #FFFFFF;
            text-align: center;
            line-height: 34px;
            margin-right: 20px;
            cursor: pointer;
        }
       .get_task {
            width: 100px;
            height: 34px;
            background: #4C7AFF;
            border-radius: 6px;
            font-weight: 400;
            font-size: 15px;
            color: #FFFFFF;
            text-align: center;
            line-height: 34px;
            margin-right: 20px;
            cursor: pointer;
        }
      .share_tasks {
            width: 100px;
            height: 34px;
            border-radius: 6px;
            border: 1px solid #1890FF;
            font-weight: 400;
            font-size: 15px;
            color: #1890FF;
            text-align: center;
            line-height: 34px;
            cursor: pointer;
        }
    }
  }
}
.details_tips {
  height: 100px;
  font-family: PingFangSC, PingFang SC;
  font-weight: 400;
  font-size: 14px;
  color: #333333;
  line-height: 20px;
  text-align: left;
  font-style: normal;
  margin-top: 30px;
}
</style>
  